import Vue from 'vue'
import Router from 'vue-router'
import index from '@/views/index'


Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      component: index,
    },
    {
      path: '/index',
      name: 'index',
      component: index,
      meta: { scrollToTop: true }
    },
    {
      path: '/search',
      name: 'search',
      component: resolve => require(['../views/search.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/standard',
      name: 'standard',
      component:  resolve => require(['../views/standard.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/tools',
      name: 'tools',
      component: resolve => require(['../views/tools.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/article',
      name: 'article',
      component: resolve => require(['../views/article.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/product',
      name: 'product',
      component: resolve => require(['../views/product.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/design',
      name: 'design',
      component: resolve => require(['../views/design.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/develop',
      name: 'develop',
      component: resolve => require(['../views/develop.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/test',
      name: 'test',
      component: resolve => require(['../views/test.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/operation',
      name: 'operation',
      component: resolve => require(['../views/operation.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/myindex',
      name: 'myindex',
      component: resolve => require(['../views/myindex.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/mydynamic',
      name: 'mydynamic',
      component: resolve => require(['../views/mydynamic.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/myfavorite',
      name: 'myfavorite',
      component: resolve => require(['../views/myfavorite.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/dynamic',
      name: 'dynamic',
      component: resolve => require(['../views/dynamic.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/favorite',
      name: 'favorite',
      component: resolve => require(['../views/favorite.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/personal',
      name: 'personal',
      component: resolve => require(['../views/personal.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/edit',
      name: 'edit',
      component: resolve => require(['../views/edit.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/details',
      name: 'details',
      component: resolve => require(['../views/details.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/details/:articleId',
      name: 'detail',
      component: resolve => require(['../views/details.vue'], resolve),
      meta: { scrollToTop: true }
    },
    {
      path: '/testpage',
      name: 'testpage',
      component: resolve => require(['../views/testpage.vue'], resolve),
      meta: { scrollToTop: true }
    },
  ],
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      // savedPosition is only available for popstate navigations.
      return savedPosition
    } else {
      // new navigation.
      // scroll to anchor
      if (to.hash) {
        return { anchor: true }
      }
      // explicitly control scroll position
      // check if any matched route config has meta that requires scrolling to top
      if (to.matched.some(m => m.meta.scrollToTop)) {
        return { x: 0, y: 0 }
      }
    }
  }

})

